﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    class FLTEKGBReport : BaseReport
    {
        #region ----------------PROPERTIES----------------------------------
        public OracleConnection OracleDB;
        public OracleCommand orlReadCommand = new OracleCommand();
        public IntexReptServBLClient proxy;
        private Dictionary<string, object> dicParamater;
        public DataSet dsResult;
        public DataSet setUI = new DataSet();
        string ABPAUFFKRS;
        string ABPAUFFLFD;
        string ABPAUFFPOS;
        string DocType;
        string CellName = "";
        string CellValue = "";
        string strCompany;
        string strExcelFile;
        #endregion
        public FLTEKGBReport()
            : base()
        {
        }
        public FLTEKGBReport(Dictionary<string, object> dicParamater)
            : base(dicParamater)
        {
            DocType = dicParamater["DocType"].ToString().Trim();
            strCompany = dicParamater["Company"].ToString().Trim();
            strExcelFile = dicParamater["ExcelFile"].ToString().Trim();
            #region Excel  columns
            columns.Add("DD");
            columns.Add("DELDATEF");
            columns.Add("DELDATE");
            columns.Add("ORDERDATE");
            columns.Add("CUSTOMER");
            columns.Add("TYPE");
            columns.Add("ORDERNO");
            columns.Add("VKPAUFPOS");
            columns.Add("ENTERUSER");
            columns.Add("ARTICLE");
            columns.Add("COLOR");
            columns.Add("ORDQTY");
            columns.Add("ALLQTY");
            columns.Add("SHIPQTY");
            columns.Add("INVQTY");
            columns.Add("OPENQTY");
            columns.Add("UNIT");
            columns.Add("REMARK");
            #endregion           						
            
        }
        #region------------------------------Function------------------------

        public void FillInExcelData(ArrayList columns, DataSet setSoruce, int xStart = 2, int yStart = 1)
        {
            try
            {
                int x = xStart, y = yStart;
                DataTable dtSoruce = setSoruce.Tables["VKPOS"];
                //exAgent.DataTableToExcel(dtSoruce, 2, 1);
                 DataTable dtOutput = new DataTable();
                 ////GABBUCHDAT	GPPARTIE	GPSPPART	GPFBPART	ORDERNO	
                 ////   LSLIEFNR	SUPPLIER	GABART	GABFARBE	GSAGARNNR	QTY

                 dtOutput.Columns.Add("GABBUCHDAT", typeof(System.String));
                 dtOutput.Columns.Add("GPPARTIE", typeof(System.String));
                 dtOutput.Columns.Add("GPSPPART", typeof(System.String));
                 dtOutput.Columns.Add("GPFBPART", typeof(System.String));
                 dtOutput.Columns.Add("ORDERNO", typeof(System.String));
                 dtOutput.Columns.Add("LSLIEFNR", typeof(System.String));
                 dtOutput.Columns.Add("SUPPLIER", typeof(System.String));
                 dtOutput.Columns.Add("GABART", typeof(System.String));
                 dtOutput.Columns.Add("GABFARBE", typeof(System.String));
                 dtOutput.Columns.Add("GSAGARNNR", typeof(System.String));
                 dtOutput.Columns.Add("QTY", System.Type.GetType("System.Decimal"));
                dtOutput.Merge(dtSoruce, false, MissingSchemaAction.Ignore);

                exAgent.DataTableToExcel(dtOutput, 3, 1);
                int count = dtOutput.Rows.Count;
                exAgent.BatchConvert2Number(3, 11, count + 2, 11);
                exAgent.SetCellValue(1, 1, "操作日期");
/*
                foreach (DataRow dataRow in dtSoruce.Rows)
                {
                    y = yStart;
                    foreach (string column in columns)
                    {
                        exAgent.SetCellValue(x, y, dataRow[column].ToString());
                        y++;
                    }
                    x++;
                }*/
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public override void WriteExcelReport(string fileType)
        {
            try
            {
                string filename = "";
                string sheetName = "";
                string Standard = "FLTEKGB";
                strExcelFile = @"FLT\FLTStandard.xls";
                string filePath = @"C:\intex.w\Report\" + strExcelFile;
                exAgent.Open(filePath);
                //exAgent.Company = strCompany;
                exAgent.strExcelFile = strExcelFile;
                string filedate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
                filename = @"采购入库退货统计" + filedate + ".xls";
                sheetName = DateTime.Now.ToShortTimeString().Replace(@":", "");
                exAgent.CreateNewSheet(filename, Standard, sheetName);
                FillInExcelData(columns, dsSource, 3, 1);
                base.WriteExcelReport("OpenExcel");
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }        
        #endregion
    }
}